//固定导航栏的js
$(function () {
  //给window绑定滚动条事件,
  $(window).on("scroll", function () {
    // 获取 不可见区域的高度
    var scrTop = $(this).scrollTop();
    // 获取 top的高度
    var topH = $(".headBigBox").height();
    //如果不可见区域的高度大于了top的高度,就让
    if (scrTop > topH) {
      // nav固定在顶部,将nav的top值设置0px,并且预留nav的高度
      $(".h-header").css({
        position: "fixed",
        top: 0,
        // "background-color": "#fff"
        
      });
      // $(".swper1").css({
      //   marginTop: $(".h-header").height(),
      // });
    } else {
      // 否则 让nav回到原来位置, 将定位设置static,并且main的预留值等于0;
      $(".h-header").css({
        position: "static",
      });
      $(".swper1").css({
        marginTop: 0,
      });
    }
  });
});
//最顶部的轮播图的js
(function () {
  class GapSwiper {
    constructor(el) {
      this.el = el;
      this.oUl = this.el.find("ul");
      this.imgIndex = 0;
      this.init();
      this.mouseHandler();
    }
    //初始化
    init() {
      //把图片的第一张,克隆到最后一张
      this.oUl.children().eq(0).clone(true).appendTo(this.oUl);
      this.autoPlay();
    }
    autoPlay() {
      this.timer = setInterval(() => {
        this.imgIndex++;
        this.autoToggle();
      }, 2000);
    }
    //根据下标进行切换
    autoToggle() {
      if (this.imgIndex > 2) {
        this.imgIndex = 1;
        this.oUl.css("left", 0);
      }
      this.oUl.animate({
        left: -this.imgIndex * this.oUl.children().eq(0).width(),
      });
    }
    mouseHandler() {
      this.el
        .mouseenter(() => {
          clearInterval(this.timer);
        })
        .mouseleave(() => {
          this.autoPlay();
        });
    }
  }
  $.fn.extend({
    swiperAuto() {
      new GapSwiper(this);
    },
  });
})();

//使用
$(function () {
  $(".bigUl").swiperAuto();
});

//回到顶部js
window.onload=()=>{
  function getScroll() {
  //ie9
  if (window.pageYOffset != undefined) {
      return {
          left: window.pageXOffset,
          top: window.pageYOffset
      }
  } else if (document.compatMode == "CSS1Compat") {
      return {
          left: document.documentElement.scrollLeft,
          top: document.documentElement.scrollTop
      }
  }
  return {
      left: document.body.scrollLeft,
      top: document.body.scrollTop
  }

}
var oRocket = document.querySelector(".tp");
//点击top 回到顶部
oRocket.onclick = function () {
  clearInterval(oRocket.timer)
  oRocket.timer = setInterval(function () {
      //目标值0
      //不可见区域的高度
      var target = 0; //目标值0
      var current = getScroll().top;//当前值
      //步长
      let steps = (target - current) / 10;
      steps = steps > 0 ? Math.ceil(steps) : Math.floor(steps);

      //让滚动条动起来 scrollTo
      window.scrollTo(0, current + steps);
      if (current == target) { //当前位置到了0,就是倒了目标位置
          clearInterval(oRocket.timer)
      }

  })

}

}
$(function(){
 
  var info=JSON.parse(sessionStorage.getItem("userInfo"))
  if(info){
    $(".h-spn").text(info.name)
    $(".delv").text("退出")
    $(".delv").text("退出").click(function(){
      alert("确认退出吗?")
      sessionStorage.clear();
      location="../index.html"
      
      $(".delv").text("登录")

    })
  }
   
  });